namespace PickGold.Charting
{
    using System;
    using System.Drawing;
    using System.Drawing.Drawing2D;
    using System.Security.Permissions;
    using System.Web;

    [SRDescription("DescriptionAttributeAnnotationPathPointCollection_AnnotationPathPointCollection"), AspNetHostingPermission(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal), AspNetHostingPermission(SecurityAction.InheritanceDemand, Level=AspNetHostingPermissionLevel.Minimal)]
    public class AnnotationPathPointCollection : ChartElementCollection<AnnotationPathPoint>
    {
        private GraphicsPath _graphicsPath;
        internal PolylineAnnotation annotation;

        public AnnotationPathPointCollection(PolylineAnnotation annotation) : base(annotation)
        {
            this.annotation = annotation;
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this._graphicsPath != null))
            {
                this._graphicsPath.Dispose();
                this._graphicsPath = null;
            }
            base.Dispose(disposing);
        }

        public override void Invalidate()
        {
            if (this.annotation != null)
            {
                if (this._graphicsPath != null)
                {
                    this._graphicsPath.Dispose();
                    this._graphicsPath = null;
                }
                if (base.Count > 0)
                {
                    PointF[] pts = new PointF[base.Count];
                    byte[] types = new byte[base.Count];
                    for (int i = 0; i < base.Count; i++)
                    {
                        pts[i] = new PointF(base[i].X, base[i].Y);
                        types[i] = base[i].PointType;
                    }
                    this._graphicsPath = new GraphicsPath(pts, types);
                }
                else
                {
                    this._graphicsPath = new GraphicsPath();
                }
                this.annotation.GraphicsPath = this._graphicsPath;
                this.annotation.Invalidate();
            }
            base.Invalidate();
        }
    }
}

